package annotation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

/**
 * @ClassName Demo02
 * @Description TODO
 * 使用反射读取注解信息
 * @Author liang
 * @Date 2018/10/17 15:02
 * @Version 1.0
 **/
public class Demo02 {

    public static void main(String [] args) throws ClassNotFoundException, NoSuchFieldException {
        Class<?> clazz = Class.forName("annotation.MyStudent");
        //获取所有注解
        Annotation[] annotations = clazz.getAnnotations();
        for (Annotation annotation:annotations){
            System.out.println("类的所有注解："+annotation.toString());
        }
        //直接通过注解类来获取  注解类
        Table table = clazz.getAnnotation(Table.class);
        System.out.println("注解table的value值："+table.value());
        //获取类的属性的注解
        Field nameAnnotation = clazz.getDeclaredField("name");
        Filed name = nameAnnotation.getAnnotation(Filed.class);
        System.out.println("列名："+name.columnName());
        System.out.println("类型："+name.type());
        System.out.println("长度："+name.length());

        //根据表名字段的信息，拼出sql，jdbc连接数据库，生产表


    }
}
